<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<script setup>
onLaunch(() => {
  // eslint-disable-next-line no-console
  console.log('mall4j.v240226')
  // #ifdef H5
  // 判断是什么系统，用于微信验签时传递参数
  uni.getSystemInfo({
    success: function (res) {
    // 客户端平台，值域为：ios、android
      if (res.platform === 'ios') {
        uni.setStorageSync('bbcIosUrl', window.location.href.split('#')[0])
      }
    }
  })
  // #endif

  const payTypeParams = {
    url: '/sys/config/paySettlementType',
    method: 'get'
  }
  http.request(payTypeParams).then(({ data }) => {
    if (data) {
      const paySettlementType = JSON.parse(data).paySettlementType
      uni.setStorageSync('bbcPaySettlementType', paySettlementType)
    }
  })
})
onShow((options) => {
  // #ifdef MP-WEIXIN
  // 通联支付从通联微信小程序返回后接收的参数
  if (uni.getStorageSync('bbcPaySettlementType') !== 1) {
    // 非通联支付模式下不处理
    return
  }
  if (options.referrerInfo && options.referrerInfo.extraData) {
    let backMerchantUrl = options.referrerInfo.extraData.backMerchantUrl
    if (backMerchantUrl) {
      backMerchantUrl = decodeURIComponent(backMerchantUrl)
      const result = backMerchantUrl.split('?')[1].split('&')
      const query = {}
      for (let i = 0; i < result.length; i++) {
        const item = result[i].split('=')
        query[item[0]] = item[1]
      }
      if (Number(query.isSignSuccess) === 1 && query.bizContent) {
        // 获取内存中的签约编号
        const acctProtocolNo = uni.getStorageSync('bbcAllinpayAcctProtocolNo')
        const bizContent = JSON.parse(decodeURIComponent(query.bizContent))
        if (bizContent.acctProtocolNo !== acctProtocolNo) {
          uni.showToast({
            title: '签约成功',
            icon: 'none'
          })
          uni.setStorageSync('bbcAllinpayAcctProtocolNo', bizContent.acctProtocolNo)
        }
      } else if (Number(query.isSignSuccess) === 0) {
        uni.showToast({
          title: '签约失败',
          icon: 'none'
        })
      }
    }
  }
  // #endif
})

// 页面不存在时触发
onPageNotFound(() => {
  uni.reLaunch({
    url: '/pages/index/index'
  })
})

</script>
<!-- eslint-disable-next-line -->
<style lang="scss">
@import './app.scss';
@import url('@/static/iconfont/iconfont.css');
</style>
